﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using iLangl.Model;

namespace iLangl.Tests.PushFixture
{
	[TestClass]
	public class SyncedOneWayDataSerializationFixture : BaseTest
	{
		[TestMethod]
		public void SyncedOneWayDataSerialization()
		{
			SyncedOneWayData sowd = new SyncedOneWayData();

			IAlert alert = Facade.Instance.AlertManager.CreateAlert(this, new Exception("Test Exception"));

			ISerializedAlert serializedAlert = Facade.Instance.AlertManager.CreateSerializedAlert(alert);

			sowd.Alerts = new ISerializedAlert[] { serializedAlert };


			SyncedDataRequestContext requestContext = new SyncedDataRequestContext();
			requestContext.SetContext(sowd);

			String sowdtext = (String)requestContext.GetContext();

			SyncedDataResponseContext responsecontext = new SyncedDataResponseContext();
			responsecontext.SetContext(sowdtext);

			SyncedOneWayData deserializedsowd = (SyncedOneWayData)responsecontext.GetContext();


			Assert.AreEqual(sowd.Alerts.Length, deserializedsowd.Alerts.Length);

			ISerializedAlert desirializedAlert = deserializedsowd.Alerts[0];

			Assert.AreEqual(serializedAlert.Id, desirializedAlert.Id);
			Assert.AreEqual(serializedAlert.Created, desirializedAlert.Created);
			Assert.AreEqual(serializedAlert.Severity, desirializedAlert.Severity);
			Assert.AreEqual(serializedAlert.Source, desirializedAlert.Source);
			Assert.AreEqual(serializedAlert.Content, desirializedAlert.Content);

		}
	}
}
